package com.fengxu.gamescript.service

import android.app.ActivityManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.os.Process
import com.fengxu.gamescript.ui.base.BaseActivity
import com.fengxu.gamescript.util.CommonUtils
import org.jetbrains.anko.doAsync
import kotlin.system.exitProcess


class SafeService : Service() {

    @Volatile
    private var useDetect:Boolean = true

    override fun onBind(intent: Intent):IBinder? = null

    override fun onCreate() {
        super.onCreate()
        doAsync {
            while (useDetect){
                if(CommonUtils.isSystemProxy(applicationContext) || CommonUtils.isVpn()){
                    BaseActivity.exitAll()
                    useDetect = false
                    break
                }
                Thread.sleep(100)
            }
        }
    }


    override fun onDestroy() {
        useDetect = false
        super.onDestroy()
    }


}